﻿@model OrderControllerModel.Address
@using (Html.BeginForm())
{
    <div class="modal-body">
        @if (Model.Order.Status != OrderStatus.WaitSellerSend)
        {
            <div class="status-box status-box-warm-alert">
                <div class="status-icon">
                    <div class="row-fluid">
                        <div class="span2">
                            <i class="icon-exclamation-sign icon-3x"></i>
                        </div>
                        <div class="span10">
                            <strong>该订单当前状态不可修改收货地址！</strong></div>
                    </div>
                </div>
            </div>
        }
        else
        { <div class="alert alert-info">
            <p>
                <strong>原收货信息：</strong><span>@(Model.Order.Receiver)</span> <span>@(Model.Order.Mobile)
                    @(Model.Order.Phone.IsNullOrEmpty() ? string.Empty : "（" + Model.Order.Phone + "）")</span></p>
            <p>
                @(Model.Order.Province)
                @(Model.Order.City)
                @(Model.Order.District)
                @(Model.Order.Address)
                (@(Model.Order.PostalCode))
            </p>
        </div>
            <p>
                <strong>新收货信息：</strong></p>
            <div>
                <div class="row-fluid">
                    <div class="span2">
                        收货地址：
                    </div>
                    <div class="span10">
                        <div>
                            @Html.DropDownList("receiver.province", Model.Province, new { id = string.Empty, @class = "span4", onchange = "areaChange(this)" })
                            @Html.DropDownList("receiver.city", Model.City, new { id = string.Empty, @class = "span4", onchange = "areaChange(this)" })
                            @Html.DropDownList("receiver.areaId", Model.District, new { id = string.Empty, @class = "span4", onchange = "areaChange(this)" })
                        </div>
                        <input name="receiver.Address" type="text" maxlength="50" class="input-large" value="@(Model.Order.Address)" />
                        <p class="help-inline">
                            街道地址（不需要填写省市区）</p>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span2">
                        收货人：
                    </div>
                    <div class="span10">
                        <input name="receiver.Name" type="text" maxlength="8" value="@(Model.Order.Receiver)" />
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span2">
                        电话号码：
                    </div>
                    <div class="span10">
                        <input name="receiver.Phone" type="text" maxlength="17" value="@(Model.Order.Phone)" />
                        <p class="help-inline">
                            格式：区号 - 电话号码 - 分机号</p>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span2">
                        手机号码：
                    </div>
                    <div class="span10">
                        <input name="receiver.Mobile" type="text" maxlength="11" value="@(Model.Order.Mobile)" />
                        <p class="help-inline">
                            电话和手机请至少填写一个
                        </p>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span2">
                        邮政编码：
                    </div>
                    <div class="span10">
                        <input id="postalCode" name="receiver.PostalCode" maxlength="6" type="text" value="@(Model.Order.PostalCode)" />
                    </div>
                </div>
            </div>}
    </div>
    <div class="modal-footer">
        <p id="message" class="pull-left">
        </p>
        <a class="btn" href="#" data-dismiss="modal">关闭</a>
        @if (Model.Order.Status == OrderStatus.WaitSellerSend)
        {
            <button type="button" class="btn btn-primary" onclick="submitMemo(this.form)">
                确 认</button>
        }
    </div>
}
@if (Model.Order.Status == OrderStatus.WaitSellerSend)
{
    @Url.Ayatta().StaticJs("china.area")

    <script type="text/javascript">
        function areaChange(obj) {
            var val = $(obj).val();
            if (val.length == 6) {
                var postalCode = _.findWhere(ChinaAreas, { Id: val }).Id;
                $("#postalCode").val(postalCode);
                return;
            }
            $(obj).nextAll('input').html("<option>请选择</option>");
            var citys = _.where(ChinaAreas, { ParentId: val });
            var array = [];
            array.push("<option>请选择</option>");
            _.each(citys, function (o) {
                array.push("<option value=" + o.Id + ">" + o.Name + "</option>");
            });
            $(obj).next().html(array.join(""));
        }


        function submitMemo(form) {
            var param = $(form).serialize();
            $.postJSON(form.action, param, function (result) {
                if (result.Status == false) {
                    $('#message', from).css('color', 'red').html(result.Message);
                }
                else {
                    $('#message', from).css('color', 'green').html("修改收货信息成功！");
                }
            });
        }
    </script>
}
